package dper.study.codes.hbase.mapper;

import com.alibaba.fastjson.JSONObject;
import dper.study.codes.elasticsearch.model.GitRepoModel;
import dper.study.codes.hbase.consts.GitRepoConsts;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;
import org.springframework.data.hadoop.hbase.RowMapper;

/**
 * Created by leichen on 2017/4/11.
 */
public class HGitRepoRowMapper implements RowMapper<GitRepoModel> {

    private Logger logger = Logger.getLogger(HGitRepoRowMapper.class) ;


    public GitRepoModel mapRow(Result result, int i) throws Exception {
        String gitRepoContent = Bytes.toString(result.getValue(
                GitRepoConsts.FAMILY_GITREPO_INFO.getBytes(),
                GitRepoConsts.COLUMN_GITREPO_CONTENT.getBytes()) );
        GitRepoModel gitRepoModel = null ;
        try{
            gitRepoModel = JSONObject.parseObject(gitRepoContent,GitRepoModel.class);
        }catch (Exception ex){
            ex.printStackTrace();
            logger.info("error");
            gitRepoModel = null ;
        }
        return gitRepoModel;
    }
}
